<template>
  <div class="div">
    <div class="box" v-for="v in arr" :key="v.id">
      <div @click="fun(v.id)">
        <img :src="v.img" />
        <div>
          <p>{{ v.text | sangedian }}</p>
          <p>{{ v.price | jiage }}</p>
          <p>{{ v.range }}</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  filters: {
    sangedian(val) {
      if (val.length > 9) {
        return val.substr(0, 9) + "...";
      } else {
        return val;
      }
    },
    jiage(val) {
      if (typeof val == "number") {
        return "￥" + val;
      } else {
        return val;
      }
    },
  },
  data() {
    return {
      arr: [
        {
          id: 111,
          img: "./img/life/erjiluyou1.png",
          text: "五粮液 第八代 浓香型 52度 500ml",
          price: 1499.0,
          range: "",
        },
        {
          id: 222,
          img: "./img/life/erjiluyou2.png",
          text: "陕西特产·巨鹰",
          price: "",
          range: "1.15km",
        },
        {
          id: 333,
          img: "./img/life/erjiluyou1.png",
          text: "五粮液 第八代 浓香型 52度 500ml",
          price: 1499.0,
          range: "",
        },
        {
          id: 444,
          img: "./img/life/erjiluyou2.png",
          text: "陕西特产·巨鹰",
          price: "",
          range: "1.15km",
        },
        {
          id: 555,
          img: "./img/life/erjiluyou1.png",
          text: "五粮液 第八代 浓香型 52度 500ml",
          price: 1499.0,
          range: "",
        },
        {
          id: 666,
          img: "./img/life/erjiluyou2.png",
          text: "陕西特产·巨鹰",
          price: "",
          range: "1.15km",
        },
      ],
    };
  },
  methods: {
    fun(val) {
      switch (val) {
        case 111:
          this.$router.push("/gooods");
          break;
        case 333:
          this.$router.push("/gooods");
          break;
        case 555:
          this.$router.push("/gooods");
          break;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.div {
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  > .box:nth-child(2n-1) {
    margin: 0.1rem 0.1rem 0.1rem 0;
  }
  > .box:nth-child(2n) {
    margin: 0.1rem 0rem 0.1rem 0.1rem;
  }
  > .box {
    width: 46%;
    background-color: #dff;
    > div {
      > img {
        width: 1.65rem;
        opacity: 0.5;
      }
      > div {
        padding: 0rem 0.05rem;
        line-height: 0.25rem;
        > p:nth-child(1) {
          font-size: 0.14rem;
        }
        > p:nth-child(2) {
          font-size: 0.16rem;
          color: red;
        }
        > p:nth-child(3) {
          font-size: 0.12rem;
          color: #999;
        }
      }
    }
  }
}
</style>